home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / alv.sun / alv.lha / src / scrload.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-08  |  6.7 KB  |  220 lines

  1. /*
  2.  * Modified by Phill Everson <everson@cs.bris.ac.uk> 29th May, 1989 for
  3.  * inclusion into the ALV toolkit.
  4.  *
  5.  */
  6.  
  7. /**************************************************************************
  8.    The program "scload" is like Sun's "screenload" program, but more
  9.    entertaining, and actually better than screenload.
  10.  
  11.    Copyright (c) 1988 by Raymond Kreisel
  12.    7/1/88 @ Suny Stony Brook
  13.  
  14.    This program may be redistributed without fee as long as this copyright
  15.    notice is intact.
  16.  
  17. ==> PLEASE send comments and bug reports to one of the following addresses:
  18.  
  19.        Ray Kreisel
  20.        CS Dept., SUNY at Stony Brook, Stony Brook NY 11794
  21.  
  22.        UUCP: {allegra, philabs, pyramid, research}!sbcs!rayk
  23.        ARPA-Internet: rayk@sbcs.sunysb.edu
  24.        CSnet: rayk@suny-sb
  25.        (If nobody is home at any of the above addresses try:
  26.         S72QKRE@TOWSONVX.BITNET                    )
  27.  
  28.  "If I get home before daylight, I just might get some sleep tonight...."
  29.  
  30. **************************************************************************/
  31. #include <pixrect/pixrect_hs.h>
  32. #include <stdio.h>
  33. #include <sys/time.h>
  34. #include <sys/types.h>
  35. #include <sys/stat.h>
  36.  
  37. #include "defs.h"
  38.  
  39. har *progname;
  40. har *filename;
  41. ixrect *pr;
  42.  
  43. #ifdef STANDALONE
  44. ain(argc, argv, envp)
  45. #else
  46. crload_main(argc, argv, envp)
  47. #endif
  48.     int argc;
  49.     char **argv;
  50.     char **envp;
  51. {
  52.     register int i, j;
  53.     int levels;
  54.     char *fb;        /* frame buffer */
  55.  
  56.     progname = strsave(argv[0]);
  57.     parse_profile(&argc, argv, envp);
  58.  
  59.     fb = strsave("/dev/fb");
  60.     while ((gc = getopt(argc, argv, "f:")) != EOF)
  61.         switch (gc) {
  62.         case 'f':
  63.             fb = strsave(optarg);
  64.             break;
  65.         case '?':
  66.             errflag++;
  67.             break;
  68.         }
  69.  
  70.     if (errflag)
  71.         error((char *) 0, "Usage: %s: [infile ...]\n", progname);
  72.  
  73.     setup_greylevelmap();
  74.  
  75.     if (optind == argc || strcmp(argv[optind], "-") == 0)
  76.         new_sc_load("", fb);
  77.     else
  78.         for (; optind < argc; optind++)
  79.             new_sc_load(argv[optind], fb);
  80. }
  81.  
  82. ew_sc_load(filename, fb)
  83.     char *filename, *fb;
  84. {
  85.     char colormapname[256];
  86.     struct rasterfile rh;
  87.     colormap_t colormap;
  88.     FILE *fp, *fopen();
  89.     int i, j, width, height, off_x, off_y;
  90.     struct pixrect *line, *screen, *screen_temp;
  91.     int sleep_time = 500;
  92.  
  93.     srand((int) time((time_t *) 0));
  94.     if (filename[0]) {
  95.         if ((fp = fopen(filename, "r")) == NULL) {
  96.             warning("%s %s", PR_IO_ERR_INFILE, filename);
  97.             return;
  98.         }
  99.     } else
  100.         fp = stdin;
  101.  
  102.     screen = pr_open(fb);
  103.     if (!screen)
  104.         error("Couldn't open screen");
  105.  
  106.     if (screen->pr_depth > 1) {
  107.         sleep_time = 0;
  108.         if (pr_load_header(fp, &rh))
  109.             error("pr_load_header failed for %s", (*filename) ? filename : "stdin");
  110.         if (pr_load_colormap(fp, &rh, &colormap))
  111.             error("pr_load_colormap failed for %s", (*filename) ? filename : "stdin");
  112.         if (!(screen_temp = pr_load_image(fp, &rh, &colormap)))
  113.             error("pr_load_image failed for %s", (*filename) ? filename : "stdin");
  114.         if (colormap.length)
  115.             pr_putcolormap(screen, 0, rh.ras_maplength / 3, colormap.map[0],
  116.                        colormap.map[1], colormap.map[2]);
  117.         else
  118.             pr_putcolormap(screen, 0, 256, greylevelmap, greylevelmap, greylevelmap);
  119.  
  120.     } else if ((screen_temp = pr_load(fp, NULL)) == NULL)
  121.         error("Error reading rasterfile header for %s", (*filename) ? filename : "stdin");
  122.  
  123.     width = screen_temp->pr_size.x;
  124.     height = screen_temp->pr_size.y;
  125.     if (screen->pr_size.x > screen_temp->pr_size.x)
  126.         off_x = (screen->pr_size.x - screen_temp->pr_size.x) / 2;
  127.     if (screen->pr_size.y > screen_temp->pr_size.y)
  128.         off_y = (screen->pr_size.y - screen_temp->pr_size.y) / 2;
  129.  
  130.     switch (rand() % 8) {
  131.     case 0:
  132.         for (j = height - 16; j > 0; j -= 16) {
  133.             pr_rop(screen, off_x, j + off_y, width, height - j, PIX_SRC, screen_temp, 0, 0);
  134.             usleep(sleep_time);
  135.         }
  136.         pr_rop(screen, off_x, off_y, width, height, PIX_SRC, screen_temp, 0, 0);
  137.  
  138.         break;
  139.     case 1:
  140.  
  141.         for (j = 0; j < height; j += 32)
  142.             for (i = 0; i < width; i += 32)
  143.                 pr_rop(screen, i + off_x, j + off_y, 16, 16, PIX_SRC, screen_temp, i, j);
  144.         for (j = 16; j < height; j += 32)
  145.             for (i = 16; i < width; i += 32)
  146.                 pr_rop(screen, i + off_x, j + off_y, 16, 16, PIX_SRC, screen_temp, i, j);
  147.         for (j = 16; j < height; j += 32)
  148.             for (i = 0; i < width; i += 32)
  149.                 pr_rop(screen, i + off_x, j + off_y, 16, 16, PIX_SRC, screen_temp, i, j);
  150.         for (j = 0; j < height; j += 32)
  151.             for (i = 16; i < width; i += 32)
  152.                 pr_rop(screen, i + off_x, j + off_y, 16, 16, PIX_SRC, screen_temp, i, j);
  153.         break;
  154.  
  155.     case 2:
  156.         for (j = height - 16; j > 0; j -= 16) {
  157.  
  158.             pr_rop(screen, off_x, off_y, width, height - j, PIX_SRC, screen_temp, 0, j);
  159.             usleep(sleep_time);
  160.         }
  161.         pr_rop(screen, off_x, off_y, width, height, PIX_SRC, screen_temp, 0, 0);
  162.         break;
  163.  
  164.     case 3:
  165.         for (j = height - 16; j > 0; j -= 16) {
  166.  
  167.             pr_rop(screen, off_x, j + off_y, width / 2, height - j, PIX_SRC, screen_temp, 0, 0);
  168.             pr_rop(screen, off_x + width / 2, off_y, width / 2, height - j, PIX_SRC, screen_temp, width / 2, j);
  169.             usleep(sleep_time);
  170.         }
  171.         pr_rop(screen, off_x, off_y, width, height, PIX_SRC, screen_temp, 0, 0);
  172.         break;
  173.     case 4:
  174.         for (j = height - 16; j > 0; j -= 16) {
  175.  
  176.             pr_rop(screen, off_x + width / 2, j + off_y, width / 2, height - j, PIX_SRC, screen_temp, width / 2, 0);
  177.             pr_rop(screen, off_x, off_y, width / 2, height - j, PIX_SRC, screen_temp, 0, j);
  178.             usleep(sleep_time);
  179.         }
  180.         pr_rop(screen, off_x, off_y, width, height, PIX_SRC, screen_temp, 0, 0);
  181.         break;
  182.  
  183.     case 5:
  184.         for (j = height - 16; j > 0; j -= 16) {
  185.  
  186.             pr_rop(screen, off_x, off_y, width / 4, height - j, PIX_SRC, screen_temp, 0, j);
  187.             pr_rop(screen, off_x + width / 4, j + off_y, width / 4 + 2, height - j, PIX_SRC, screen_temp, width / 4, 0);
  188.             pr_rop(screen, off_x + width / 4 * 3, j + off_y, width / 4, height - j, PIX_SRC, screen_temp, width / 4 * 3, 0);
  189.             pr_rop(screen, off_x + width / 2, off_y, width / 4, height - j, PIX_SRC, screen_temp, width / 2, j);
  190.             usleep(sleep_time);
  191.         }
  192.         pr_rop(screen, off_x, off_y, width, height, PIX_SRC, screen_temp, 0, 0);
  193.         break;
  194.     case 6:
  195.         for (j = height - 16; j > 0; j -= 16) {
  196.  
  197.             pr_rop(screen, off_x, off_y, width / 4, height - j, PIX_SRC, screen_temp, 0, j);
  198.             pr_rop(screen, off_x + width / 4, j + off_y, width / 4, height - j, PIX_SRC, screen_temp, width / 4, 0);
  199.             pr_rop(screen, off_x + width / 2, j + off_y, width / 4, height - j, PIX_SRC, screen_temp, width / 2, 0);
  200.             pr_rop(screen, off_x + width / 4 * 3, off_y, width / 4, height - j, PIX_SRC, screen_temp, width / 4 * 3, j);
  201.             usleep(sleep_time);
  202.         }
  203.         pr_rop(screen, off_x, off_y, width, height, PIX_SRC, screen_temp, 0, 0);
  204.         break;
  205.  
  206.     case 7:
  207.         for (j = 16; j < width / 2; j += 16) {
  208.  
  209.             pr_rop(screen, off_x + width / 2 - j, off_y, j, height, PIX_SRC, screen_temp, 0, 0);
  210.             pr_rop(screen, off_x + width / 2, off_y, j, height, PIX_SRC, screen_temp, width - j, 0);
  211.             usleep(sleep_time);
  212.         }
  213.         pr_rop(screen, off_x, off_y, width, height, PIX_SRC, screen_temp, 0, 0);
  214.         break;
  215.     }
  216.     pr_destroy(screen_temp);
  217.     pr_close(screen);
  218.     fclose(fp);
  219. }
  220.